sdks/rust: add Rust SDK with identical examples#193
Open
Conversation
Mirrors the surface of the Python and TypeScript SDKs:
- Sandbox::create / connect / kill / hibernate / wake / set_timeout
- commands().run, .start, .background, .attach, .list, .kill (WebSocket
streaming over the same multiplexed binary protocol used by the other
SDKs: 0x01 stdout, 0x02 stderr, 0x03 exit, 0x04 scrollback_end,
0x00 stdin)
- files().{read, read_bytes, write, list, make_dir, remove, exists}
- Template::{build, list, get, delete}
- Checkpoint + preview URL CRUD on Sandbox
- signed download_url / upload_url
Examples are 1:1 ports of the existing Python/TypeScript suites:
- test_commands.rs (9 sub-tests, mirrors test_commands.py)
- test_file_ops.rs (8 sub-tests, mirrors test_file_ops.py)
- test_python_sdk.rs (mirrors test_python_sdk.py)
Each example creates a fresh sandbox, runs the suite, and tears the
sandbox down — they double as integration tests against a real backend
once OPENCOMPUTER_API_KEY/OPENCOMPUTER_API_URL are set:
cargo run --example test_commands
cargo run --example test_file_ops
cargo run --example test_python_sdk
Offline checks (run in CI):
cargo fmt --check
cargo clippy --all-targets -- -D warnings
cargo build --all-targets
cargo test --tests
A new GitHub workflow (.github/workflows/test-rust-sdk.yml) runs all
four on PRs that touch sdks/rust.
Docs
----
- New navigation group "Rust SDK" in docs/docs.json
- New reference pages: docs/reference/rust-sdk/{overview,sandbox,exec,filesystem}.mdx
These mirror the structure of the TS/Py reference and document the
exact public surface (SandboxOpts, RunOpts, ExecStartOpts, StreamEvent,
EntryInfo, ProcessResult, ExecSession, etc.)
- Add Rust tabs to the existing CodeGroups in:
docs/introduction.mdx
docs/quickstart.mdx
docs/sandboxes/running-commands.mdx
docs/sandboxes/working-with-files.mdx
- Root README: drop the inline TOML hint and instead show a real Rust
quickstart alongside the TS one.
Examples
--------
- examples/rust/ — small Cargo project that depends on the local SDK by
path. src/main.rs mirrors examples/test.py and examples/test.ts
line-for-line so the three feel like the same demo across languages.
(Sits at src/main.rs because bin/ is globally gitignored.)
SDK
---
- Re-export ExecSession, ExecStartOpts, and StreamEvent from lib.rs so
the streaming API documented in the new reference pages is actually
reachable from outside the crate.
- Extend tests/smoke.rs to assert those types are public + matchable.
- README.md: add a streaming snippet using the now-exported types.
CI
--
- Workflow now builds examples/rust as a second cargo project and runs
fmt-check on both. Path filters cover both sdks/rust/** and
examples/rust/**.
All offline checks pass locally on rustc 1.94:
cargo fmt --check (sdks/rust + examples/rust)
cargo clippy --all-targets -- -D warnings
cargo build --all-targets (SDK)
cargo build (examples/rust)
cargo test --tests (4/4 pass)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a Rust SDK at
sdks/rust/that mirrors the surface of the existing Python and TypeScript SDKs.Surface
Sandbox::create/connect/kill/hibernate/wake/set_timeoutsandbox.commands().run,.start,.background,.attach,.list,.kill— WebSocket streaming uses the same multiplexed binary protocol as the other SDKs (0x00stdin,0x01stdout,0x02stderr,0x03exit,0x04scrollback_end)sandbox.files().{read, read_bytes, write, list, make_dir, remove, exists}Template::{build, list, get, delete}Sandboxdownload_url/upload_urlPublic API matches the Python/TS SDKs idiom-by-idiom:
commandsis preserved as an alias forexecfor parity.Examples (1:1 ports of the existing suites)
examples/test_commands.rssdks/python/examples/test_commands.py/test-commands.tsexamples/test_file_ops.rssdks/python/examples/test_file_ops.py/test-file-ops.tsexamples/test_python_sdk.rssdks/python/examples/test_python_sdk.pyEach example creates a fresh sandbox, runs the suite, and tears the sandbox down. They exit non-zero on any failed check, so they double as integration tests.
CI
New workflow
.github/workflows/test-rust-sdk.ymlruns on PRs touchingsdks/rust/**:cargo fmt --checkcargo clippy --all-targets -- -D warningscargo build --all-targetscargo test --tests(offline smoke tests intests/smoke.rs)All four pass locally on rustc 1.94.
Test plan
cargo fmt --checkcleancargo clippy --all-targets -- -D warningscleancargo build --all-targetsbuilds lib + 3 examplescargo test --testsrunstests/smoke.rs(3/3 pass — builder threading, JSON round-trip)OPENCOMPUTER_API_KEYto confirm the live integration paths work end-to-end (this needs a backend; the offline tests only exercise local logic).Notes for reviewers
Cargo.lockis not committed (library convention);target/is gitignored.https://claude.ai/code/session_01AbHiVWdsRLggibaXK4DRHF
Generated by Claude Code